﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Hospital_Tra_hospital_contract : System.Web.UI.Page,HZ.MBSM.BLL.TraDes
{
    String CMProjectId;
    Int64 CMHospitalId;
    protected void Page_Load(object sender, EventArgs e)
    {
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (_Account != null)
        {
            CMProjectId = SysFun.IsSQL(Request.QueryString["ProjectId"]);
            CMHospitalId = SysFun.ToLong(_Account.AccountId);
            if (!IsPostBack)
            {
                
                Db db = new Db();
                System.Data.IDataReader dr;
                dr = db.DataReader("select count(*) as id from hospital_contract where  ProjectId=" + CMProjectId + " and  hospital_id=" + CMHospitalId);
                while (dr.Read())
                {
                    if (SysFun.ToInt(dr["id"]) != 0)
                    {
                        dr.Close();
                        dr = db.DataReader("select Contract_stat_date,Contract_end_date,Contract_PayTime from hospital_contract where  ProjectId=" + CMProjectId + " and  hospital_id=" + CMHospitalId.ToString());
                        dr.Read();
                        txtcontractStartDate.Text = Convert.ToDateTime(dr["Contract_stat_date"].ToString()).ToShortDateString();
                        txtcontractEndDate.Text = Convert.ToDateTime(dr["Contract_end_date"].ToString()).ToShortDateString();
                        txtPaytime.Text = dr["Contract_PayTime"].ToString();

                    }
                }
                dr.Close();
                dr.Dispose();
                db.Close();
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string strStr = "";
        if (SysFun.IsNumeric(txtPaytime.Text))
        {
            Db db = new Db();
            System.Data.IDataReader dr;
            dr = db.DataReader("select count(*) as id from hospital_contract where  ProjectId=" + CMProjectId + " and  hospital_id=" + CMHospitalId.ToString());
            while (dr.Read())
            {
                if (SysFun.ToInt(dr["id"]) != 0)
                {
                    strStr = "Update hospital_contract set Contract_stat_date='" + txtcontractStartDate.Text + "',Contract_end_date='" + txtcontractEndDate.Text + "',Contract_PayTime='" + txtPaytime.Text + "' Where ProjectId=" + CMProjectId + " and  hospital_id=" + CMHospitalId.ToString();
                }
                else
                {
                    strStr = "Insert into hospital_contract values(" + CMProjectId + "," + CMHospitalId.ToString() + ",'" + txtcontractStartDate.Text + "','" + txtcontractEndDate.Text + "','" + txtPaytime.Text + "')";
                }
            }
            dr.Close();
            dr.Dispose();
            db.Command(strStr);

            db.Close();
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新、插入", "hospital_contract、hospital_contract", strStr, "../Hospital_Tra_hospital/contract.aspx");
            Response.Write("<script>alert('修改成功！');</script>");
        }
        else
        {
            Response.Write("<script>alert('回款时间输入有误！');</script>");
        }
        
    }

    #region TraDes 成员

    public string Name
    {
        get { return "合同要素填写"; }
    }

    public string Describe
    {
        get { return ""; }
    }

    public string ParentName
    {
        get { return "合同管理"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumHospitale);
            return _AccountType;
        }
    }

    #endregion
}
